<?php

use App\Modules\Admin\Controllers\AuthController;
use App\Modules\Admin\Controllers\DepartmentController;
use App\Modules\Admin\Controllers\DictController;
use App\Modules\Admin\Controllers\DictTypeController;
use App\Modules\Admin\Controllers\MenuController;
use App\Modules\Admin\Controllers\RoleController;
use App\Modules\Admin\Controllers\UserController;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider and all of them will
| be assigned to the "api" middleware group. Make something great!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

// Route::middleware('auth:sanctum')->group(function () {

// });


Route::get('/', function () {
    return 'admin';
});

Route::group([
    'prefix' => 'public',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::group([
        'prefix' => 'auth'
    ], function() {

    });
});

Route::group([
    'prefix' => 'auth',

], function() {
    Route::group([
        'middleware' => [
            'auth:sanctum'
        ]
    ], function() {
        Route::get('user-info', [AuthController::class, 'userInfo']);
        Route::delete('logout', [AuthController::class, 'logout']);

    });
    Route::get('captcha', [AuthController::class, 'captcha'])->name('new.test');
    Route::post('login', [AuthController::class, 'login']);
});

Route::group([
    'prefix' => 'menu',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::get('routes', [MenuController::class, 'routes']);
    Route::get('', [MenuController::class, 'index'])->name('sys:menu:list');
    Route::post('', [MenuController::class, 'add'])->name('sys:menu:add');
    Route::put('{id}', [MenuController::class, 'edit'])->name('sys:menu:edit');
    Route::delete('{id}', [MenuController::class, 'del'])->name('sys:menu:del');
    Route::get('options', [MenuController::class, 'options'])->name('sys:menu:options');
    Route::get('{id}', [MenuController::class, 'detail'])->name('sys:menu:detail');
});

Route::group([
    'prefix' => 'dept',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::get('', [DepartmentController::class, 'index'])->name('sys:user:list');
    Route::post('', [DepartmentController::class, 'add'])->name('sys:user:add');
    Route::put('{id}', [DepartmentController::class, 'edit'])->name('sys:user:edit');
    Route::delete('{id}', [DepartmentController::class, 'del'])->name('sys:user:del');
    Route::get('options', [DepartmentController::class, 'options'])->name('sys:user:options');
    Route::get('{id}', [DepartmentController::class, 'detail'])->name('sys:user:detail');
});

Route::group([
    'prefix' => 'user',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::get('/', [UserController::class, 'index'])->name('sys:user:list');
    Route::post('/', [UserController::class, 'add'])->name('sys:user:add');
    Route::put('{id}', [UserController::class, 'edit'])->name('sys:user:edit');
    Route::patch('{id}', [UserController::class, 'password'])->name('sys:user:password');
    Route::delete('{id}', [UserController::class, 'del'])->name('sys:user:del');
    Route::get('options', [UserController::class, 'options'])->name('sys:user:options');
    Route::get('{id}', [UserController::class, 'detail'])->name('sys:user:detail');
});

Route::group([
    'prefix' => 'role',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::get('/', [RoleController::class, 'index'])->name('sys:role:list');
    Route::post('/', [RoleController::class, 'add'])->name('sys:role:add');
    Route::put('{id}', [RoleController::class, 'edit'])->name('sys:role:edit');
    Route::delete('{id}', [RoleController::class, 'del'])->name('sys:role:del');
    Route::get('options', [RoleController::class, 'options'])->name('sys:role:options');
    Route::get('{id}', [RoleController::class, 'detail'])->name('sys:role:detail');
    Route::get('{roleId}/menuIds', [RoleController::class, 'menuIds'])->name('sys:role:menu-ids');
    Route::put('{roleId}/menus', [RoleController::class, 'menus'])->name('sys:role:menus');
});

Route::group([
    'prefix' => 'dict',
    'middleware' => [
        'auth:sanctum'
    ]
], function() {
    Route::get('/', [DictController::class, 'index'])->name('sys:dict:list');
    Route::post('/', [DictController::class, 'add'])->name('sys:dict:add');
    Route::put('{id}', [DictController::class, 'edit'])->name('sys:dict:edit');
    Route::delete('{id}', [DictController::class, 'del'])->name('sys:dict:del');
    Route::get('/{typeCode}/options', [DictController::class, 'options'])->name('sys:dict:options');
    Route::get('{id}', [DictController::class, 'detail'])->name('sys:dict:detail');


    Route::get('type/page', [DictTypeController::class, 'index'])->name('sys:dict_type:list');
    Route::post('type', [DictTypeController::class, 'add'])->name('sys:dict_type:add');
    Route::put('type/{id}', [DictTypeController::class, 'edit'])->name('sys:dict_type:edit');
    Route::delete('type/{id}', [DictTypeController::class, 'del'])->name('sys:dict_type:del');
    Route::get('type/{id}', [DictTypeController::class, 'detail'])->name('sys:dict_type:detail');
});








